package com.andy.permission.interceptor

import android.app.Activity
import com.andy.logcat.LogUtils
import com.hjq.permissions.IPermissionInterceptor
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions

/**
 * Author:Andy
 * Date:2023/3/23 13:57
 * Description:PermissionInterceptor
 */
class PermissionInterceptor(callBack: ((isNotAskAgain: Boolean) -> Unit)? = null) : IPermissionInterceptor {
    private val mCallback = callBack

    override fun launchPermissionRequest(activity: Activity, allPermissions: MutableList<String>, callback: OnPermissionCallback?) {
        super.launchPermissionRequest(activity, allPermissions, callback)
        val deniedPermissions = XXPermissions.getDenied(activity, allPermissions)
        LogUtils.e("开始申请权限-----deniedPermissions=${deniedPermissions}")
    }

    override fun grantedPermissionRequest(activity: Activity, allPermissions: MutableList<String>, grantedPermissions: MutableList<String>, allGranted: Boolean, callback: OnPermissionCallback?) {
        super.grantedPermissionRequest(activity, allPermissions, grantedPermissions, allGranted, callback)
        LogUtils.e("允许权限----grantedPermissions=${grantedPermissions}--allGranted=${allGranted}")
    }

    override fun deniedPermissionRequest(activity: Activity, allPermissions: MutableList<String>, deniedPermissions: MutableList<String>, doNotAskAgain: Boolean, callback: OnPermissionCallback?) {
        super.deniedPermissionRequest(activity, allPermissions, deniedPermissions, doNotAskAgain, callback)
        mCallback?.invoke(doNotAskAgain)
        LogUtils.e("拒绝权限请求----allPermissions=${allPermissions}--deniedPermissions=${deniedPermissions}---doNotAskAgain=${doNotAskAgain}")
    }

    override fun finishPermissionRequest(activity: Activity, allPermissions: MutableList<String>, skipRequest: Boolean, callback: OnPermissionCallback?) {
        super.finishPermissionRequest(activity, allPermissions, skipRequest, callback)
        LogUtils.e("结束权限请求----allPermissions=${allPermissions}--skipRequest=${skipRequest}")
    }

}